<?php
	// ----------------------------------------------------
	// Beschreibung Skript:
	//   Gibt den aktuellen Benutzer aus und speichert 
	//   Änderungen an diesem Benutzer.
	//
	// ----------------------------------------------------
	// Änderungen:
	//
	// ----------------------------------------------------


	// ------------------------------------------------------
	// Initialisiert das Skript.
	// ------------------------------------------------------  
	require_once 'loader.php';

	// ------------------------------------------------------
	// Verarbeitet POST Daten und speichert diese.
	// ------------------------------------------------------  
 	$ExterUserID = 'michelle.rangosch';
// 	$ExterUserID = 'andy';
	$LoggedUserID = 'michelle.rangosch';
//  	$ExterUserID = 'werner.pfister';
	//
	if(strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
		If (isset($_POST['ExternalUserID'])) {
			$ExterUserID = htmlspecialchars($_POST['ExternalUserID']);
		}
	} 
	
	$Member->getUserData($ExterUserID, $LoggedUserID);


	// ------------------------------------------------------
	// Header laden.
	// ------------------------------------------------------  
	$Header->printHeader();
	
	// ------------------------------------------------------
	// Benutzerdaten laden.
	// ------------------------------------------------------  
	// Print personal data.
	$isSuperUser = $Member->isSuperAdmin();
//  	If ($Member->Birthday != NIL) { 
//  		$birthday = new DateTime($Member->Birthday); 
//  		$birthday = $birthday->format('d.m.Y');
//  	}
	$arrLabel = Array('Geb.:', 'Adresse:', 'PLZ, Ort:', 'Tel. P:', 'Tel. G:', 'Mobile:', 'E-Mail P:', 'E-Mail G:', 'Webseite P:', 'Webseite G:');
	$arrValue = Array($Member->Birthday, $Member->Address->Address, $Member->Address->PLZ.' '.$Member->Address->City,
					  $Member->Contact->TelefonPrivate, $Member->Contact->TelefonBusiness, $Member->Contact->TelefonMobile,
					  $Member->Contact->EmailPrivate, $Member->Contact->EmailBusiness, 
					  $Member->Contact->WebsitePrivate, $Member->Contact->WebsiteBusiness);
	//
	print('<form Action="set_user.php" method="post">'."\n");
	print('<input type="hidden" name="ExternalUserID" value="'.$ExterUserID.'">'."\n");
	print('<table border="0">'."\n");
	print('  <tbody>'."\n");
	print('    <tr>'."\n");
	print('      <td valign="top" rowspan="'.(count($arrValue)+1).'" width="120">'."\n");
	print('        <img src="'.$Member->ImagePath.'" alt="'.$Member->UserName.'" width="'.strval($Member->ImageWidth).'" height="'.strval($Member->ImageHeigth).'"><br />'."\n");
	print('      </td>'."\n");
	print('      <td width="150">Vorname, Name:</td>'."\n");
	print('      <td width="150">'.$Member->FirstName.' '.$Member->LastName.'</td>'."\n");
	print('    </tr>'."\n");
	For ($ix = 0; $ix < count($arrLabel); $ix++) {
		If ($arrValue[$ix] != '') {
			print('    <tr>'."\n");
			print('      <td>'.$arrLabel[$ix].'</td>'."\n");
			print('      <td>'.$arrValue[$ix].'</td>'."\n");
			print('    </tr>'."\n");
		}
	}
	print('    <tr>'."\n");
	print('      <td>&nbsp;</td><td>&nbsp;</td><td align="right"><input type="submit" value="Bearbeiten"></td>'."\n");
	print('    </tr>'."\n");
	print('  </tbody>'."\n");
	print('</table>'."\n");
	print('</form>'."\n");
	//
	print("<br />"."\n");
	//
	// Print committee, job and License data.
	$arrLabel = Array('Mitgliederbeitrag:', 'Mitgliederstatus:', 'Familienflag:', 
					  'Lizenz(en):', 'Lizenznummer(n):', 'Aufgabe(n):', 'Vorstand:', 'User-Status:');
	$arrValue = Array(number_format($Member->MemberFee, 2, '.', '\''), $Member->MemberState, $Member->FamilyFlag?'Ja':'Nein', 
					  $Member->Associations->getAssociationsAsString(), $Member->Associations->getAssociationIDsAsString(), 
					  $Member->Jobs->getJobsAsString(), $Member->CommitteeTasks->getCommitteeTasksAsString(), $Member->State?'Aktiv':'Inaktiv');
	//
	print('<form Action="set_memberdata.php" method="post">'."\n");
	print('<input type="hidden" name="ExternalUserID" value="'.$ExterUserID.'">'."\n");
	print('<table border="0">'."\n");
	print('  <tbody>'."\n");
	For ($ix = 0; $ix < count($arrLabel); $ix++) {
		If (strlen($arrValue[$ix]) > 0) {
			print('    <tr>'."\n");
			print('      <td width="120">&nbsp;</td>'."\n");
			print('      <td width="150" valign="top">'.$arrLabel[$ix].'</td>'."\n");
			print('      <td width="150">'.$arrValue[$ix].'</td>'."\n");
			print('    </tr>'."\n");
		}
	}
	if ( 1==1 ) {
		print('    <tr>'."\n");
		print('      <td>&nbsp;</td><td>&nbsp;</td><td align="right"><input type="submit" value="Bearbeiten"></td>'."\n");
		print('    </tr>'."\n");
		print('  </tbody>'."\n");
		print('</table>'."\n");
		print('</form>'."\n");
	}
	
	// ------------------------------------------------------
	// Footer laden.
	// ------------------------------------------------------  
	include 'footer.php';
?>